package Controller;

import Util.JDBCUtill;
import javafx.fxml.FXML;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import pojo.classroom;

import java.sql.SQLException;
import java.time.LocalDate;

public class ClassroomUpdateController {

    private static classroom current;
    @FXML
    private TextField Equipment;

    @FXML
    private TextField Capacity;

    @FXML
    private DatePicker Available;

    @FXML
    private TextField StartTimeFile;
    @FXML
    private TextField EndTimeFile;
    @FXML
    private TextField CId;

    @FXML
    public static void setCurrent(classroom current){
        ClassroomUpdateController.current=current;
    }
    @FXML
    void initialize() {
    CId.setText(current.getCId());
    Capacity.setText(String.valueOf(current.getCapacity()));
    Equipment.setText(current.getEquipment());
    Available.setValue(LocalDate.parse(current.getAvailable()));
    StartTimeFile.setText(current.getStartTime());
    EndTimeFile.setText(current.getEndTime());
    }
    @FXML
    void upDateTODB() throws SQLException {
        JDBCUtill.delete(current.getCId());//delete
        classroom classroom = new classroom(CId.getText(),Integer.parseInt(Capacity.getText()),
                Equipment.getText(), Available.getValue().toString(),StartTimeFile.getText(),EndTimeFile.getText());
        JDBCUtill.addDate(classroom);
        initialize();
        Main.changeView("ClassRoom.fxml");
    }

}
